<template>
  <div>
    <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="200px">
      <el-form-item label="进货单号" prop="purOrderNumber">
        <el-input v-model="formData.purOrderNumber" placeholder="请输入进货单号" clearable :style="{width: '300px'}">
        </el-input>
      </el-form-item>
      <el-form-item label="供货商id" prop="purSupplierId">
        <el-input v-model="formData.purSupplierId" placeholder="请输入供货商id" clearable :style="{width: '300px'}">
        </el-input>
      </el-form-item>
      <el-form-item label="进货单价价格" prop="purUnitPrice">
        <el-input-number v-model="formData.purUnitPrice" placeholder="请输入进货单价价格" :precision='2'>
        </el-input-number>
      </el-form-item>
      <el-form-item label="供应商接应人员姓名" prop="purSupplierContactName">
        <el-input v-model="formData.purSupplierContactName" placeholder="请输入供应商接应人员姓名" clearable
          :style="{width: '300px'}"></el-input>
      </el-form-item>
      <el-form-item label="进货日期" prop="purDate">
        <el-date-picker v-model="formData.purDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
          :style="{width: '300px'}" placeholder="请选择进货日期" clearable></el-date-picker>
      </el-form-item>
      <el-form-item label="进货的商品id" prop="purProductId">
        <el-input v-model="formData.purProductId" placeholder="请输入进货的商品id" clearable :style="{width: '300px'}">
        </el-input>
      </el-form-item>
      <el-form-item label="进货的数量" prop="purQuantity">
        <el-input v-model="formData.purQuantity" placeholder="请输入进货的数量" clearable :style="{width: '300px'}">
        </el-input>
      </el-form-item>
      <el-form-item label="进货人员id" prop="purBuyerId">
        <el-input v-model="formData.purBuyerId" placeholder="请输入进货人员id" clearable :style="{width: '300px'}">
        </el-input>
      </el-form-item>
      <el-form-item label="进货车辆车牌号" prop="purVehiclePlate">
        <el-input v-model="formData.purVehiclePlate" placeholder="请输入进货车辆车牌号" clearable
          :style="{width: '300px'}"></el-input>
      </el-form-item>
      <el-form-item label="进货路线" prop="purRoute">
        <el-input v-model="formData.purRoute" placeholder="请输入进货路线“格式为：地方-地方-地方”" clearable
          :style="{width: '300px'}"></el-input>
      </el-form-item>
      <el-form-item label="进货到达哪个仓库id" prop="purWarehouseId">
        <el-select v-model="formData.purWarehouseId" placeholder="请输入进货到达哪个仓库id" clearable
          :style="{width: '300px'}">
          <el-option v-for="(item, index) in purWarehouseIdOptions" :key="index" :label="item.label"
            :value="item.value" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="仓库接收负责人id" prop="purWarehouseReceptionistId">
        <el-input v-model="formData.purWarehouseReceptionistId" placeholder="请输入仓库接收负责人id" clearable
          :style="{width: '300px'}"></el-input>
      </el-form-item>
      <el-form-item label="进货是否完成" prop="purPurchase">
        <el-select v-model="formData.purPurchase" placeholder="请输入进货是否完成" clearable :style="{width: '300px'}">
          <el-option v-for="(item, index) in purPurchaseOptions" :key="index" :label="item.label"
            :value="item.value" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item size="large">
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import request from "@/utils/request";

export default {
  components: {},
  props: [],
  data() {
    return {
      formData: {
        purOrderNumber: undefined,
        purSupplierId: undefined,
        purUnitPrice: 0,
        purSupplierContactName: undefined,
        purDate: null,
        purProductId: undefined,
        purQuantity: undefined,
        purBuyerId: undefined,
        purVehiclePlate: undefined,
        purRoute: undefined,
        purWarehouseId: undefined,
        purWarehouseReceptionistId: undefined,
        purPurchase: undefined,
      },
      rules: {
        purOrderNumber: [{
          required: true,
          message: '请输入进货单号',
          trigger: 'blur'
        }],
        purSupplierId: [{
          required: true,
          message: '请输入供货商id',
          trigger: 'blur'
        }],
        purUnitPrice: [{
          required: true,
          message: '请输入进货单价价格',
          trigger: 'blur'
        }],
        purSupplierContactName: [{
          required: true,
          message: '请输入供应商接应人员姓名',
          trigger: 'blur'
        }],
        purDate: [{
          required: true,
          message: '请选择进货日期',
          trigger: 'change'
        }],
        purProductId: [{
          required: true,
          message: '请输入进货的商品id',
          trigger: 'blur'
        }],
        purQuantity: [{
          required: true,
          message: '请输入进货的数量',
          trigger: 'blur'
        }],
        purBuyerId: [{
          required: true,
          message: '请输入进货人员id',
          trigger: 'blur'
        }],
        purVehiclePlate: [{
          required: true,
          message: '请输入进货车辆车牌号',
          trigger: 'blur'
        }],
        purRoute: [{
          required: true,
          message: '请输入进货路线“格式为：地方-地方-地方”',
          trigger: 'blur'
        }],
        purWarehouseId: [{
          required: true,
          message: '请输入进货到达哪个仓库id',
          trigger: 'change'
        }],
        purWarehouseReceptionistId: [{
          required: true,
          message: '请输入仓库接收负责人id',
          trigger: 'blur'
        }],
        purPurchase: [{
          required: true,
          message: '请输入进货是否完成',
          trigger: 'change'
        }],
      },
      purWarehouseIdOptions: [{
        "label": "仓库1",
        "value": 1
      }, {
        "label": "仓库2",
        "value": 2
      }, {
        "label": "仓库3",
        "value": 3
      }],
      purPurchaseOptions: [{
        "label": "未完成",
        "value": 0
      }, {
        "label": "完成",
        "value": 1
      }],
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    submitForm() {
      this.$refs['elForm'].validate(valid => {
        if (!valid) return
        addPurchase(this.formData).then(response => {
          this.$modal.msgSuccess("新增成功");
        });
        // TODO 提交表单
      })
    },
    resetForm() {
      this.$refs['elForm'].resetFields()
    },
  }
}
// 新增进货
export function addPurchase(data) {
  return request({
    url: '/purchase/purchase',
    method: 'post',
    data: data
  })
}
</script>
<style>
</style>
